﻿var mciValue = new Object();
var dcdValue = new Object();
$(initPage);
function initPage() {

	$("#btnEdit").click(function() {
		$(".mci").each(function(){
			var id = $(this).attr("id");
			mciValue["mci" + id] = $(".mci_" + id + "[checked]").val();
			$("input", this).attr("disabled",false);
		});
		
		$(".dcd").each(function(){
			var id = $(this).attr("id");
			dcdValue["dcd" + id] = $(".dcd_" + id + "[checked]").val();
			$("input", this).attr("disabled",false);
		});

		$("#btnEdit").attr("disabled", true);
		$("#btnSave,#btnCancle").attr("disabled",false);
	});
	
	$("#btnSave").click(function() {
		var mciStrs = [];
		$(".mci").each(function(){
			var id = $(this).attr("id");
			mciStrs[mciStrs.length] = id + ";" + $(".mci_" + id + "[checked]").val();
		});
		var dcdStrs = [];
		$(".dcd").each(function(){
			var id = $(this).attr("id");
			dcdStrs[dcdStrs.length] = id + ";" + $(".dcd_" + id + "[checked]").val();
		});
		$.post("m/submit_conf/modify_check", {
			mciStrs:mciStrs,
			dcdStrs:dcdStrs
		}, function(data) {
			if ($.checkErrorMsg(data) ) {
				alert("系统提示：" + data.msg.text);
				$(".mci").each(function(){
					var id = $(this).attr("id");
					mciValue["mci" + id] = $(".mci_" + id + "[checked]").val();
					$("input", this).attr("disabled",true);
				});
				
				$(".dcd").each(function(){
					var id = $(this).attr("id");
					dcdValue["dcd" + id] = $(".dcd_" + id + "[checked]").val();
					$("input", this).attr("disabled",true);
				});
				
				$("#btnCancle,#btnSave").attr("disabled", true);
				$("#btnEdit").attr("disabled",false);
			} 
		}, "json");
	});
	
	$("#btnCancle").click(function() {
		$(".mci").each(function(){
			var id = $(this).attr("id");
			$("input", this).each(function(){
				$(this).attr("checked", this.value == mciValue["mci" + id]).attr("disabled",true);
			});
		});
		
		$(".dcd").each(function(){
			var id = $(this).attr("id");
			$("input", this).each(function(){
				$(this).attr("checked", this.value == dcdValue["dcd" + id]).attr("disabled",true);
			});
		});
		$("#btnCancle,#btnSave").attr("disabled", true);
		$("#btnEdit").attr("disabled",false);
	});
}